let state = {
  isCollapse: false,
  islogin: sessionStorage.getItem("islogin")
    ? Boolean(sessionStorage.getItem("islogin"))
    : false,
  username: sessionStorage.getItem("username")
    ? sessionStorage.getItem("username")
    : "",
  //权限信息
  role: []
};
let mutations = {
  setNoRefresh(state) {
    state.IsRefresh = false; // 设置不刷新
  },
  openLeftMenu: function(state) {
    state.isCollapse = !state.isCollapse;
  },
  //登陆成功的状态
  logsuccess(state, data) {
    //改变登录状态
    state.islogin = true;
    //存储用户名
    sessionStorage.setItem("islogin", true);
    //设置权限
    state.role = JSON.parse(sessionStorage.getItem("power"));
    window.sessionStorage.setItem("islogin", true);
    window.sessionStorage.setItem("power", JSON.stringify(data.power_name));
    window.sessionStorage.setItem(
      "username",
      JSON.stringify(data.admin_username)
    );
  },
  //注销
  loginEdit(state) {
    // 注销
    state.isLogin = false;
    state.role = [];
    window.sessionStorage.setItem("islogin", false);
    window.sessionStorage.removeItem("power");
    window.sessionStorage.removeItem("username");
  }
};
let getters = {
  getrole(state) {
    return state.role;
  },
  getuser(state) {
    return state.username;
  },
  getislogin(state) {
    return state.islogin;
  }
};
let actions = {
  openMenu: function({ commit }) {
    commit("openLeftMenu");
  },
  setNorefresh({ commit }) {
    commit("setNorefresh");
  },
  loginSuccess({ commit }, data) {
    commit("logsuccess", data);
  },
  loginEdit({ commit }) {
    commit("loginEdit");
  }
};
export default {
  state,
  getters,
  actions,
  mutations
};
